import os
import sys
import argparse
HOME = os.getenv('HOME')
#SETUP_FILE = '%s/SiFive/git/configs/freedom-e-sdk/setup-toolchain.sh' % HOME
SETUP_FILE = '%s/git/configs/freedom-e-sdk/setup-toolchain.sh' % HOME
print(SETUP_FILE)

USAGE = 'python ~/git/configs/freedom-e-sdk/setup-freedom-e-sdk.py -g ~/git/configs/haps/centos/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-centos6 -o ~/git/configs/haps/centos/riscv-openocd-0.10.0-2019.08.2-x86_64-linux-centos6  -q ~/git/configs/haps/centos/riscv-qemu-4.1.0-2019.08.0-x86_64-linux-centos6/bin/ '

parser = argparse.ArgumentParser()
parser.add_argument('-g', '--gcc',  help='gcc path')
parser.add_argument('-o', '--ocd',  help='openocd path')
parser.add_argument('-q', '--qemu', help='qemu path')

args = parser.parse_args()
print(args)

with open(SETUP_FILE, 'w') as f:
    if args.gcc:
        print(args.gcc)
        path_gcc = 'export RISCV_PATH=%s\n' % args.gcc
        f.write(path_gcc)
    if args.ocd:
        print(args.ocd)
        path_ocd = 'export RISCV_OPENOCD_PATH=%s\n' % args.ocd
        f.write(path_ocd)
    if args.qemu:
        print(args.qemu)
        print(os.getenv('PATH'))
        if args.qemu not in os.getenv('PATH'):
            path_qemu = 'export PATH=$PATH:%s\n' % args.qemu
            f.write(path_qemu)

f.close()
